// pages/experience/experienceSort/experienceSort.js
import Http from '../../../utils/http.js';
const http = new Http();
const app = getApp();
Page({
    /**
     * 页面的初始数据
     */
    data: {
        bgImg: [
            '../../../images/experience/zhianyujing.png',
            '../../../images/experience/zongjiao.png',
            '../../../images/experience/suo.png',
            '../../../images/experience/biaoqing.png',
            '../../../images/experience/shandian.png',
            '../../../images/experience/xingqubulas.png',
            '../../../images/experience/feiji.png',
            '../../../images/experience/tongyong.png',
            '../../../images/experience/qita.png',
        ],
        // 经验分类数组
        experiencTypeArr: [],
        permissionList: ['00', '01'],
    },
    editBtn() {
        wx.navigateTo({
            url: `./editExperienceTypeList/editExperienceTypeList`,
        });
    },
    experienceContentTap(e) {
        wx.navigateTo({
            url: `../../homePageInfo/experienceDotsList/experienceDotsList?extypeid=${e.currentTarget.dataset.id}&title=${e.currentTarget.dataset.title}`,
        });
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.getExperienceTypeList();
    },
    onShow: function () {},
    refresh() {
        this.setData({
            experiencTypeArr: [],
        });
        this.getExperienceTypeList();
    },
    //获取经验类别列表
    getExperienceTypeList() {
        let _that = this;
        http.getRequest(
            `cjMap/getExperienceTypeList?authId=${app.globalData.authId}`
        ).then((res) => {
            if (res.status == 0) {
                for (let i = 0; i < res.data.length; i++) {
                    let listItem = {
                        type: '',
                        count: 0,
                        iconPath: '',
                        id: '',
                    };
                    listItem.type = res.data[i].typename;
                    listItem.count = res.data[i].num;
                    listItem.id = res.data[i].id;
                    if (i > 6) {
                        if (i == res.data.length - 1) {
                            listItem.iconPath = _that.data.bgImg[8];
                        } else {
                            listItem.iconPath = _that.data.bgImg[7];
                        }
                    } else {
                        listItem.iconPath = _that.data.bgImg[i];
                    }
                    _that.data.experiencTypeArr.push(listItem);
                }
                _that.setData({
                    experiencTypeArr: _that.data.experiencTypeArr,
                });
            }
        });
    },
});
